package array;

import java.util.Arrays;

public class L977 {
    /* public int[] sortedSquares(int[] nums) {
         for (int i=0;i<nums.length;i++){

             nums[i]=nums[i]*nums[i];
         }
         Arrays.sort(nums);
         return nums;
     }*/
    //卡尔双指针法
    public int[] sortedSquares(int[] nums) {
        int[] ints = new int[nums.length];
        int k=ints.length-1;
        int i=0,j=ints.length-1;
        while (i<=j){
            if (nums[i]*nums[i]>nums[j]*nums[j]){
                ints[k--]=nums[i]*nums[i];
                i++;
            }else {
                ints[k--]=nums[j]*nums[j];
                j--;

            }


        }

        return ints;

    }
}
